﻿Public Class BaseControl : Inherits UserControl

	Overridable Function Errors() As String
		Return ""
	End Function

	Dim _Active As Boolean
	Public Overridable Property Active As Boolean
		Get
			Return _Active
		End Get
		Set(Value As Boolean)
			_Active = Value
			For Each Control In Controls
				If TypeOf Control Is BaseControl Then Control.Active = Value
			Next
			SetBackColor()
		End Set
	End Property

	Sub SetBackColor()
		BackColor = If(Not Enabled, Themes.Current.ReadOnlyColor, If(Active, If([ReadOnly], Themes.Current.ReadOnlyColor, SystemColors.Window), Themes.Current.ReadOnlyColor))
		ForeColor = If(Active, Color.Black, Themes.Current.LabelColor)
		For Each Control As Control In Controls
			Control.BackColor = BackColor
		Next
	End Sub

	Event GenericEvent(Sender As Object, EventType As GenericEventType, Param As String)

	Dim _ReadOnly As Boolean
	Property [ReadOnly]() As Boolean
		Get
			Return _ReadOnly
		End Get
		Set(ByVal Value As Boolean)
			_ReadOnly = Value
			OnReadOnlyChanged()
			Invalidate()
		End Set
	End Property

	Public Sub RaiseChangeEvent()
		RaiseEvent GenericEvent(Me, GenericEventType.Change, "")
	End Sub

	Sub RaiseActionEvent(Action As String)
		RaiseEvent GenericEvent(Me, GenericEventType.Action, Action)
	End Sub

	Sub RaiseActivateEvent()
		RaiseEvent GenericEvent(Me, GenericEventType.Activate, "")
	End Sub

	Overridable Sub OnReadOnlyChanged()

	End Sub

	Public Property MissingMessage As String

	Public Overridable Sub Reset()

	End Sub

	Public Property IsRequired As Boolean

	ReadOnly Property Process() As Process
		Get
			Dim Obj As Object = Me
			Do Until TypeOf Obj Is ProcessBase
				If Obj Is Nothing Then Return Nothing
				Obj = Obj.Parent
			Loop
			Return Obj
		End Get
	End Property

	Public Property Caption As String

End Class
